<?php

declare(strict_types=1);

namespace Plugin\Attractions\AttractionManagement\Model\Attraction_type;

use App\Exception\BusinessException;
use App\Http\Common\ResultCode;
use Hyperf\DbConnection\Model\Model;
use Plugin\Attractions\AttractionManagement\Constant;

/**
 * @property int $id 
 * @property int $type 类型0:点位，1:信息
 * @property string $name 分类名称
 * @property string $description 分类描述
 * @property int $sort 排序
 * @property int $parent_id 父级分类Id
 * @property int $level 分类层级
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class AttractionType extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'attraction_type';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'type', 'name', 'description', 'sort', 'parent_id', 'level', 'created_at', 'updated_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'type' => 'integer', 'sort' => 'integer', 'parent_id' => 'integer', 'level' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function updating(\Hyperf\Database\Model\Events\Updating $event)
    {
        if (in_array($this->id, array_column(Constant::DEFAULT_SPOT_TYPE, 'id'))) {
            throw new BusinessException(ResultCode::NOT_ACCEPTABLE, '默认类型不允许修改');
        }
    }
}
